﻿$(document).ready(function () {
    touchEndEvent = "ontouchend" in document ? "touchend" : "mouseup";

    chords.init();
});
var touchEndEvent;
var chords = {
    knownSongs: [],

    init: function () {
        $.get("./songs/tabsList.xml", function (xml) {
            console.log('got the file');
            $(xml).find('TabFile').each(function () {
                chords.knownSongs.push(
                {
                    name: $(this).find('Name').text(),
                    description: $(this).find('Title').text()
                });
            });
            chords.fillList();
        });
    },
    
    fillList: function () {
        $("#songslist").empty();
        $.each(chords.knownSongs, function () {
            var newItem = $("#template-items").clone();

            // Now fill in the fields with the data
           // var currentProduct = newItem.find(".prodToEdit");
            newItem.find(".songName").attr('song', this.name);
            newItem.find(".songName").text(this.description);

            // And add the new list item to the page
            newItem.children().appendTo("#songslist");

        });
        $("#songslist .songName").bind(touchEndEvent, function (e) {
            e.preventDefault();
            chords.showChords(this);
        });
    },

    showChords: function (chord) {
        // transition($("#songs-overview"), 'fade');
        window.kendoMobileApplication.navigate("#songs-chord");
        // todo : assign the values
        chords.showSongContents($(chord).attr('song'));
    },

    showSongContents: function (songName) {
        $("#pageHeader").data("kendoMobileNavBar").title(songName);
        $('#songs-chord').attr('data-title', songName);
        $('#tabsContent').html('loading...' + songName);
        $.get("./songs/" + songName, function (xml) {
            
            $('#tabsContent').html('<pre>' + $(xml).find('Content').text() + '</pre>');
        });
    }
};


var $has = {  
    touch: "ontouchend" in document,
    orientation: "onorientationchange" in window,
    geolocation: typeof navigator.geolocation != "undefined",
    transitions: "WebKitTransitionEvent" in window,
    canvas: !!document.createElement("canvas").getContext,
    audio: !!document.createElement("audio").canPlayType,
    localStorage: "localStorage" in window
     
};

